package com.itboye.ihomebank.adapter;

import java.util.Iterator;
import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.Toast;

import com.itboye.ihomebank.R;
import com.itboye.ihomebank.bean.YuYueListBean;
import com.itboye.ihomebank.support.commonadapter.MutiplyCommonAdapter;
import com.itboye.ihomebank.support.commonadapter.ViewHolder;
import com.itboye.ihomebank.util.TimesUtils;
import com.itboye.ihomebank.util.XImageLoader;

/***
 * 示例adapter
 * 
 * @author mr.w
 * 
 */
public class YuYueListAdapter extends MutiplyCommonAdapter<YuYueListBean> {

	int position;
	List<YuYueListBean> datas;

	public YuYueListAdapter(Context context, List<YuYueListBean> datas,
			int... layoutId) {
		super(context, datas, layoutId);
		// TODO Auto-generated constructor stub
		this.datas = datas;
	}

	@Override
	public int getItemViewType(int position) {
		// TODO Auto-generated method stub

		return 0;
	}

	@Override
	public void convert(ViewHolder holder, final YuYueListBean t, int type,
			final int position) {
		// TODO Auto-generated method stub
		holder.setText(R.id.name_txt, "姓名：" + t.getRealname());

		holder.setText(R.id.timebegin_txt,
				"开始时间：" + TimesUtils.getStringToDateTwo(t.getStarttime()) + "");
		holder.setText(R.id.timeend_txt,
				"结束时间：：" + TimesUtils.getStringToDateTwo(t.getEndtime()) + "");
		holder.setText(R.id.beizhu_txt, "备注：" + t.getMark() + "");
		holder.setTag(R.id.select_img, t.isSelect());
		holder.setOnClickListener(R.id.select_img, position,
				new OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						Iterator<YuYueListBean> iterator = datas.iterator();
						while (iterator.hasNext()) {
							YuYueListBean yuYueListBean = (YuYueListBean) iterator
									.next();
							if (yuYueListBean.getId().equals(t.getId())) {
								t.setSelect(!t.isSelect());
								notifyDataSetChanged();
								break;
							}

						}
					}
				});
		if (t.isSelect()) {
			holder.setBackgroundRes(R.id.select_img, R.drawable.unselect);
		} else {
			holder.setBackgroundRes(R.id.select_img, R.drawable.select);
		}
		XImageLoader.load(t.getHead(),
				(ImageView) holder.getView(R.id.head_img));
	}

	@Override
	public void getItemPosition(int position) {
		// TODO Auto-generated method stub
		this.position = position;
	}

}
